package com.qiahao.socket;

import com.qiahao.constant.Cons;
import com.qiahao.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.File;
import java.net.URI;

/**
 * Created by Administrator on 2018/3/29 0029.
 */
@Component
public class SocketRuner implements CommandLineRunner {



    @Autowired
    QuestionService questionService;

    @Override
    public void run(String... strings) throws Exception {
        try

        {
            WebSocketContainer container = ContainerProvider.getWebSocketContainer(); // 获取WebSocket连接器，其中具体实现可以参照websocket-api.jar的源码,Class.forName("org.apache.tomcat.websocket.WsWebSocketContainer");
            Session session = container.connectToServer(Client.class, new URI(Cons.socketUrl)); // 连接会话


//            for (int i=0;i<100000;i++){
//               String result =questionService.getQuestionResult(new File("D:\\1522316914435id85.mp3"), 88l);
//
//               System.out.print("语结果:第"+i+"个,结果"+result);
//            }

        } catch(Exception e)
        {

        }
    }
}
